home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr05 / picbuttn.zip / README.TXT < prev   
Text File  |  1993-07-03  |  4KB  |  65 lines

  1. Here is a simple way to create the elegant "picture" buttons which grace
  2. sophisticated programs... the buttons which have a picture or miniature 
  3. icon instead of a caption.  
  4.  
  5. To test and view the demo program: copy the file PICBUTNS.FRM to your normal
  6. VB workspace.  Start VB, and from new project, select ADD FILE, with 
  7. PICBUTNS.FRM as the target.  Remove the default FORM1.FRM from the project.
  8. Your project should now consist of a blank GLOBAL.BAS and PICBUTNS.FRM.
  9. Run the program.  You will see a button with a pile of yellow poker chips,
  10. which will click properly with the action of the mouse.  How its done...
  11.  
  12. To generate this style of button in VB, at least in this simplistic mode,
  13. requires three picture boxes.  The first is the actual button which will
  14. be visible to the user.  This is the top button on PICBUTNS.FRM.  On the
  15. demo, this is picture1.  The lower left picture box, picture2, is
  16. the "up" picture, and picture3, the "down" picture.  These latter
  17. 2 have their visible properties set to "0" or FALSE, so they are not seen
  18. at run time.  Clicking picture1 at run time generates two events
  19. in sequence... the mousedown event and the mouseup event.  At mousedown,
  20. the code replaces picture1.picture with picture3.picture (the down picture)
  21. At mouseup, the picture is again replaced, this time with picture2.picture,
  22. the up picture.  The code you wish to execute belongs after this swap.  See
  23. the comments in the code at the picture1_mouseup event.
  24.  
  25. The pictures are very easy to make.  The two icon files represent the blank
  26. up and down states of the button.  Use iconworks to view them if you wish.
  27. You don't need to make the buttons icon sized (you can manually bitmap them
  28. instead with paintbrush) but it is much easier and convenient to do so.
  29. Heres the easiest method, from the beginning, to make a picture button.
  30.  
  31. On a blank form, create three picture boxes.  Set the autosize property to
  32. TRUE for all three.  Set the VISUAL property to false for the last two.  Now
  33. run iconworks alongside VB, and load the two icons, button1.ico and 
  34. button2.ico in two blank workspaces.  In a third icon workspace, create the
  35. picture you wish to appear on the button, but make it at least 4 pixels
  36. smaller than a full icon, and leave the background white.  Using the EDIT
  37. tools on iconworks, COPY the picture you have drawn and PASTE it smack in
  38. the middle of button1.ico (the up button).  PASTE it again on button2.ico,
  39. but move it, relative to the position you pasted it on button1.ico, exactly
  40. 2 pixels right and 1 pixel down.  This generates the downward motion when
  41. the user clicks your button.  Remember when you COPY your picture to limit
  42. the size of the copy to just your picture, and none of the blank
  43. surrounding it.  Otherwise, you will copy over the necessary greys of the
  44. buttons and the shadowing will be lost.
  45.  
  46. You should now have two icons which represent the up and down button states
  47. on iconworks.  All the white and grey shadowing should be intact, and the
  48. picture you drew will be displaced on the down icon 2 pixels right and 1
  49. pixel down.  Copy the ENTIRE up button icon and paste it into picture1
  50. and picture2 on your VB form.  Copy the entire down button icon and paste
  51. this one into picture3.  Save the icons if you wish.
  52.  
  53. Examine the code for the picture1_mousedown and picture1_mouseup events, and
  54. it should be obvious how the coding works.  The main drawback to this system
  55. is the number of controls involved.  I wouldn't care to create more than 3
  56. or 4 picture buttons on a form in this manner, but just one is enough to
  57. set your project apart from other VB programs.
  58.  
  59. My name is Kurt Bjorn, and I am a pilot for American Airlines, currently
  60. living in Evanston.  I would love to exchange ideas, especially for 
  61. VISUAL BASIC.  This program amazes me with its elegance, power, and
  62. simplicity.  Drop me a message on the AQUILA BBS, in the WINDOWS
  63. conference, J 6, especially if you have any questions on this technique
  64. (or maybe you have a better way!)  I'd like to hear from you.
  65.